from django.db import models

DIFFICULTY_CHOICES = (
    (u'E',  u'Easy'),
    (u'M',  u'Moderate'),
    (u'H',  u'Hard'),
    (u'VH', u'Very Hard'),
)

class Race(models.Model):
    name       = models.CharField(max_length=200)
    start_date = models.DateField()
    end_date   = models.DateField()

    def __unicode__(self):
        return self.name

class Leg(models.Model):
    race       = models.ForeignKey(Race)
    name       = models.CharField(max_length=40)
    order      = models.IntegerField(default='1')
    notes      = models.CharField(max_length=200, blank=True)
    difficulty = models.CharField(max_length=2, choices=DIFFICULTY_CHOICES)
    length     = models.FloatField("Length (miles)")
    elev_gain  = models.IntegerField("Elev. gain (ft)")
    elev_loss  = models.IntegerField("Elev. loss (ft)")

    def __unicode__(self):
        return self.name

    def elev_change(self):
        return self.elev_gain - self.elev_loss
